using System.Linq;
using Blackbird.Common.Exceptions;
using Blackbird.Core;
using Blackbird.Core.Editable.Frames;
using Blackbird.Core.Editable.Sprites;
using Blackbird.Core.Entities.Sprites;
using Microsoft.Xna.Framework.Content.Pipeline;

namespace Blackbird.Pipeline
{
    /// <summary>
    /// This class will be instantiated by the XNA Framework Content Pipeline
    /// to apply custom processing to content data, converting an object of
    /// type TInput to TOutput. The input and output types may be the same if
    /// the processor wishes to alter data without changing its type.
    ///
    /// This should be part of a Content Pipeline Extension Library project.
    ///
    /// </summary>
    [ContentProcessor(DisplayName = "Blackbird.Pipeline.MultispriteProcessor")]
    public class MultispriteProcessor : ContentProcessor<EditableMultisprite, MultiSprite>
    {
        public override MultiSprite Process(EditableMultisprite input, ContentProcessorContext context)
        {
            var sprite = new MultiSprite
                             {
                                 Name = input.Name
                             };

            var processor = new FramesetProcessor();
            foreach (EditableFramesetList editableFramesetList in input)
            {
                var list = new FramesetList();
                list.AddRange(editableFramesetList.Select(editableFrameset => processor.Process(editableFrameset, context)));

                sprite.FramesetListCollection.Add(list);
            }

            return sprite;
        }
    }
}